<template>
  <div>
    <sort-bar>
      <template #left>相似歌曲</template>
    </sort-bar>
    <loader v-if="!songlist"></loader>
    <div
      v-else
      v-for="item in songlist"
      :key="item.index"
      @click="clickToSong(item.id)"
      class="recommend-song"
    >
      <img :src="item.album.picUrl" :alt="item.name" />
      <div class="recommend-song-title">
        <p>{{item.name}}</p>
        <p>by {{item.artists[0].name}}</p>
      </div>
    </div>
  </div>
</template>

<script>
import SortBar from '@/components/content/sortbar/SortBar'
import Loader from '@/components/common/loader/Loader'

export default {
  components: {
    SortBar,
    Loader
  },
  props: {
    songlist: {
      type: Array,
      default() {
        return []
      }
    }
  },
  methods: {
    // 点击推荐跳转至对应歌曲
    clickToSong(id) {
      this.$router.push('/discover/song/detail?id=' + id)
    }
  }
}
</script>

<style scoped>
.sort-bar {
  border-bottom: 1px solid #999;
}
.sort-bar >>> .left {
  flex: 14;
  color: #000;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.recommend-song {
  display: flex;
  margin: 10px 0;
  cursor: pointer;
}

img {
  width: 50px;
  height: 50px;
}

.recommend-song-title {
  margin-left: 10px;
  font-size: 13px;
}
.recommend-song-title p {
  width: 98px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  margin: 5px 0;
}
.recommend-song-title p:nth-child(2) {
  color: #888;
}
</style>